package com.ccnu.JobHub.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ccnu.JobHub.model.database.ViewPost;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ViewPostMapper extends BaseMapper<ViewPost> {
    /**
     * 搜索升学帖
     * @param search 搜索内容
     * @param offset 当前页码
     * @param pageSize 页面大小
     * @param type 最新还是最热
     * @return 返回一个list
     */
    @Select("SELECT * FROM enrollment_post WHERE title LIKE CONCAT('%', #{search}, '%') OR content LIKE CONCAT('%', #{search}, '%') AND status = 1 order by ${type} desc LIMIT #{offset}, #{pageSize}")
    List<ViewPost> searchEnrollmentPost(@Param("search") String search, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize, @Param("type") String type);

    /**
     * 显示升学帖
     * @param offset 当前页码
     * @param pageSize 页面大小
     * @return 返回一个list
     */
    @Select("SELECT * FROM enrollment_post where status = 1 order by ${type} desc limit #{offset},#{pageSize}")
    List<ViewPost> listEnrollmentPost( @Param("offset") Integer offset, @Param("pageSize") Integer pageSize, @Param("type") String type);

    /**
     * 搜索就业帖
     * @param search 搜索内容
     * @param offset 当前页码
     * @param pageSize 页面大小
     * @return 返回一个list
     */
   @Select("SELECT * FROM job_post where title like CONCAT('%',#{search},'%') or content like CONCAT('%',#{search},'%') AND status = 1 order by ${type} desc limit #{offset},#{pageSize}")
    List<ViewPost> searchJobPost(@Param("search") String search, @Param("offset") Integer offset, @Param("pageSize") Integer pageSize, @Param("type") String type);

    /**
     * 显示就业帖
     * @param offset 当前页码
     * @param pageSize 页面大小
     * @return 返回一个list
     */
    @Select("SELECT * FROM job_post where status = 1 order by ${type} desc limit #{offset},#{pageSize}")
    List<ViewPost> listJobPost( @Param("offset") Integer offset, @Param("pageSize") Integer pageSize, @Param("type") String  type);
}
